home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr53
/
pctv4n_1.zip
/
XQLDICT.C
< prev
next >
Wrap
Text File
|
1993-06-11
|
8KB
|
345 lines
/**************************************************
* FILE NAME: XQLdict.c TITLE: dictionary listing
*
* AUTHOR: K. E. North II, Resource Group, Inc.
*
* SYNOPSIS:
*
* List record structure info for Netware SQL
* / XQL tables
*
***************************************************
* NOTE - requires XQLMINTF interface module
***************************************************
*
* initialize (strings, counts, error_status)
* assign variables to table, view
*
* initiate data base connection -
* dbConnect() to login, get cursor
* execute SQL
* dbRequest() - compile SQL statement
*
* IF status <> 0 then
* while <> end of data:
* get dictionary info (dbDescribe)
* format and list columns
* ELSE
* process system error message
* ENDIF
* terminate data base connection: dbClose()
*
***************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include "xqlintf.h"
#include "xqldefs.h"
#include "xqlvarbl.h"
#ifndef __XQLFUNCS_H
#include "xqlfuncs.h"
#endif
#ifndef __DBTYPES_H
#include "dbtypes.h"
#endif
#ifndef __REQUEST_H
#include "request.h"
#endif
#ifndef __XCOLINFO_H
#include "xcolinfo.h"
#endif
#undef DEBUG
#undef DEBUG1
#define RCOUNT 10
#define DISPLAYLEN 20
int SQLCODE; /* XQL status code */
int ExitStatus;
int StatusReturned;
void GetArgs(int, char *, char *, char *, char *);
static char DBDictPath[80];
static char DBTable[32];
char *table;
char *dict;
COLUMNS ColInfo[MAXFIELD];
COLUMNS *fi;
struct ConnectionInfo *si;
struct ViewInfo *vu;
struct SQLRequest *rq;
void main (int argc, char *argv[])
{
int flen; /* string length of field name */
int i; /* blank fill loop index */
int TotalLength; /* sum of field lengths */
static char SQLString[MAXSQL];
static char DictColName[DISPLAYLEN+1];
char *ColDataType;
si = calloc(1, sizeof(struct ConnectionInfo));
vu = calloc(1, sizeof(struct ViewInfo));
rq = calloc(1, sizeof(struct SQLRequest));
/* initialize strings */
memset(SQLString,'\x0',sizeof(SQLString));
memset(DBDictPath,'\x0',sizeof(DBDictPath));
memset(DBTable,'\x0',sizeof(DBTable));
table = &DBTable[0];
dict = &DBDictPath[0];
SQLCODE = SQL_SUCCESS; /* zero XQLM SQLCODE */
StatusReturned = SQL_SUCCESS;
GetArgs(argc,argv[1],argv[2],table,dict);
/*******************************************/
/* open data base - login, get 1st cursor */
/*******************************************/
strcpy (si->data_path, DBDictPath);
strcpy (si->dict_path, DBDictPath);
StatusReturned = dbConnect (si);
if ((StatusReturned == NOXQLP))
{
printf
("\n<XQLdict> ERROR %d: \n",
StatusReturned);
printf
("\n Neither XQLP nor NSREQ is loaded.\n");
exit (1);
}
if ((StatusReturned == NOXQLM))
{
printf
("\n<XQLdict> ERROR %d: \n",
StatusReturned);
printf
("\n Neither XQLM nor NSREQ is loaded.\n");
exit (1);
}
if ((StatusReturned != SQL_SUCCESS))
{
printf
("\n<XQLdict> ERROR %d: Unable to open %s",
StatusReturned, DBDictPath);
exit (1);
}
/* specify query string */
strcpy(SQLString,"SELECT * FROM ");
strcat(SQLString,DBTable);
/* save request string */
strcpy(rq->Statement,SQLString);
/************************/
/* compile and execute */
/************************/
SQLCODE = SQL_SUCCESS;
StatusReturned = SQL_SUCCESS;
StatusReturned = dbRequest(rq);
if ((StatusReturned != SQL_SUCCESS))
{
if (StatusReturned < 0 )
{
printf
("\n<XQLdict> STATUS: compiling %s\n",
SQLString);
}
else
{
printf
("\n<XQLdict> ERROR: compiling %s\n",
SQLString);
exit (1);
}
}
/************************/
/* get dictionary */
/************************/
printf ("\nStructure for table: %s\n", DBTable);
printf ("Column Column Name Type\
Width Dec Int.Size\n");
SQLCODE = SQL_SUCCESS;
StatusReturned = SQL_SUCCESS;
ColPosition = 0;
vu->ColCount = 0;
TotalLength = 0;
vu->RowLength = 2; /* column lengths + separators */
do
{
/* point to column descriptor */
fi = &ColInfo[ColPosition];
StatusReturned = SQL_SUCCESS;
/* get data dictionary for
the current cursor ID */
StatusReturned =
dbDescribe( ColPosition,
fi, rq );
if ((StatusReturned != SQL_SUCCESS))
{
if (StatusReturned == INVALIDPOS)
{
break;
}
else
{
printf
("\n<XQLdict> ERROR %d: \n",
StatusReturned);
printf
("\n getting data dictionary for %s\n",
SQLString);
exit (1);
}
};
vu->ColCount++; /* update column count */
/* re-calc row length */
vu->RowLength +=
ColInfo[ColPosition].Width + 2;
/* re-calc cols length */
TotalLength +=
ColInfo[ColPosition].Width;
ColDataType = DecodeXQLDataType(fi->DataType);
strcpy(DictColName,fi->ColName);
flen = strlen(fi->ColName);
for ( i=flen; i < DISPLAYLEN; i++ );
{
DictColName[i]='\x20';
}
DictColName[DISPLAYLEN]='\x0';
printf
("\n %3d %20.20s %12.12s %5d %2d %5d",
vu->ColCount,
DictColName,
ColDataType,
fi->Width,
fi->Scale,
fi->Size);
ColPosition++;
}
while (StatusReturned == SQL_SUCCESS);
/* display summary */
printf
("\nTotal: %d Maximum View Length: %d\n",
TotalLength, vu->RowLength);
/****************/
/* close */
/****************/
SQLCODE = SQL_SUCCESS;
StatusReturned = dbClose ();
if ( StatusReturned )
{
printf
("\n<XQLdict> ERROR %d: \n",
StatusReturned);
printf
("\n dbClose failed, CursorID: %d\n",
rq->CursorID);
exit (1);
}
}
/**************************************************
* FUNCTION NAME: GetArgs
*
* AUTHOR: Ken North
*
* SYNOPSIS:
*
* get table name and dictionary path from
* command line or user
*
***************************************************/
void GetArgs(int argc, char *arg1, char *arg2,
char *table, char *dict)
{
static char name [80];
if (argc > 1)
{
memset(name,'\x0',sizeof(name));
if (*arg1 == '?')
{
printf("\n Usage: XQLDICT table \
dictionarypath\n");
printf ("\n XQLDICT Netware SQL / XQL \
data definitions\n");
printf(" (Requires Btrieve and Netware SQL \
or XQL)\n\n");
printf
(" To display a screen at a time, type:\n");
printf
(" XQLDICT table dictionarypath | \
MORE\n\n");
printf
(" To list to a file, type:\n");
printf
(" XQLDICT table dictionarypath > \
listfile\n\n\n");
exit(1);
}
strcpy (name, arg1);
strupr (name); /* translate to upper case */
strcpy(table,name) ; /* copy name to table */
memset(name,'\x0',sizeof(name));
}
if (argc > 2)
{
strcpy (name, arg2);
strupr (name); /* translate to upper case */
strcpy(dict,name) ;
}
if (argc < 2)
{
printf ("Table name ? ");
gets (name);
puts ("\n");
strupr (name); /* translate to upper case */
strcpy(table,name) ;
memset(name,'\x0',sizeof(name)); /* zero name */
printf ("Dictionary pathname ? ");
gets (name);
puts ("\n");
strupr (name);
strcpy(dict,name) ;
}
}